package com.charging.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.charging.common.annotation.Log;
import com.charging.common.core.controller.BaseController;
import com.charging.common.core.domain.AjaxResult;
import com.charging.common.enums.BusinessType;
import com.charging.system.domain.KxRechargeScheme;
import com.charging.system.service.IKxRechargeSchemeService;
import com.charging.common.utils.poi.ExcelUtil;
import com.charging.common.core.page.TableDataInfo;

/**
 * 充值规则Controller
 *
 * @author charging
 * @date 2024-04-19
 */
@RestController
@RequestMapping("/system/charging_scheme")
public class KxRechargeSchemeController extends BaseController
{
    @Autowired
    private IKxRechargeSchemeService kxRechargeSchemeService;

    /**
     * 查询充值规则列表
     */
    @PreAuthorize("@ss.hasPermi('system:charging_scheme:list')")
    @GetMapping("/list")
    public TableDataInfo list(KxRechargeScheme kxRechargeScheme)
    {
        startPage();
        List<KxRechargeScheme> list = kxRechargeSchemeService.selectKxRechargeSchemeList(kxRechargeScheme);
        return getDataTable(list);
    }

    /**
     * 导出充值规则列表
     */
    @PreAuthorize("@ss.hasPermi('system:charging_scheme:export')")
    @Log(title = "充值规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KxRechargeScheme kxRechargeScheme)
    {
        List<KxRechargeScheme> list = kxRechargeSchemeService.selectKxRechargeSchemeList(kxRechargeScheme);
        ExcelUtil<KxRechargeScheme> util = new ExcelUtil<KxRechargeScheme>(KxRechargeScheme.class);
        util.exportExcel(response, list, "充值规则数据");
    }

    /**
     * 获取充值规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:charging_scheme:query')")
    @GetMapping(value = "/{rechargeSchemeId}")
    public AjaxResult getInfo(@PathVariable("rechargeSchemeId") Long rechargeSchemeId)
    {
        return success(kxRechargeSchemeService.selectKxRechargeSchemeByRechargeSchemeId(rechargeSchemeId));
    }

    /**
     * 新增充值规则
     */
    @PreAuthorize("@ss.hasPermi('system:charging_scheme:add')")
    @Log(title = "充值规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KxRechargeScheme kxRechargeScheme)
    {
        return toAjax(kxRechargeSchemeService.insertKxRechargeScheme(kxRechargeScheme));
    }

    /**
     * 修改充值规则
     */
    @PreAuthorize("@ss.hasPermi('system:charging_scheme:edit')")
    @Log(title = "充值规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KxRechargeScheme kxRechargeScheme)
    {
        return toAjax(kxRechargeSchemeService.updateKxRechargeScheme(kxRechargeScheme));
    }

    /**
     * 删除充值规则
     */
    @PreAuthorize("@ss.hasPermi('system:charging_scheme:remove')")
    @Log(title = "充值规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rechargeSchemeIds}")
    public AjaxResult remove(@PathVariable Long[] rechargeSchemeIds)
    {
        return toAjax(kxRechargeSchemeService.deleteKxRechargeSchemeByRechargeSchemeIds(rechargeSchemeIds));
    }
}
